#!/usr/bin/env node

const fs = require('fs'),
      src = process.argv[2],
      dst = process.argv[3];
if(!fs.existsSync(src)){
  console.error('%s not exits!', src);
  process.exit(1);
}
if(!fs.statSync(src).isFile()){
  console.error('%s is not file!', src);
}
if(typeof dst === 'undefined'){
  console.error('dst is undefined');
  process.exit(3);
}
//复制文件内容
let srcStream = fs.createReadStream(src),
    dstStream = fs.createWriteStream(dst);
srcStream.pipe(dstStream);
//复制文件权限
srcStream.on('close', () => {
  fs.chmodSync(dst, fs.statSync(src).mode);
});
